//
//  SunBankDetailVC.m
//  Xspcf
//
//  Created by sunshine on 2017/7/20.
//  Copyright © 2017年 小小算盘. All rights reserved.
//

#import "SunBankDetailVC.h"
#import "SunBankDetailListVC.h"

@interface SunBankDetailVC ()
{
    UITextField *_bankDetail;
}
@end

@implementation SunBankDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置开户行联行号";
    self.view.backgroundColor = BACKGROUND;
    [self creatUI];
    // Do any additional setup after loading the view.
}

- (void)creatUI{
    NSDictionary *dic = [Sun getUser:USER];
    UIView *view = [[UIView alloc]init];
    [self.view addSubview:view];
    [view lt_Top:SunEdgesMake(Y(50), 0, 0, Y(51)) to:nil save:YES];
    view.backgroundColor = WHITE;
    UILabel *label = [[UILabel alloc]init];
    [view addSubview:label];
    [label lt_setLeft:X(20) to:nil save:YES];
    [label lt_YcenterTo:nil save:YES];
    label.text = @"提现银行卡";
    label.textColor = GRAY;
    label.font = [UIFont systemFontOfSize:14];
    UILabel *bank = [[UILabel alloc]init];
    [view addSubview:bank];
    [bank lt_setLeft:X(120) to:nil save:YES];
    [bank lt_YcenterTo:nil save:YES];
    bank.text = [NSString stringWithFormat:@"%@(尾号%@)",[dic objectForKey:@"bank"],[[dic objectForKey:@"bankCard"] substringFromIndex:[[dic objectForKey:@"bankCard"]length] - 4]];
    bank.textColor = GRAY;
    bank.font = [UIFont systemFontOfSize:14];
    UIView *line = [[UIView alloc]init];
    [view addSubview:line];
    line.backgroundColor = LINE;
    [line lt_Bottom:SunEdgesMake(X(15), 0, X(15), 0.5) to:nil save:YES];
    UIView *view2 = [[UIView alloc]init];
    [self.view addSubview:view2];
    [view2 lt_Top:SunEdgesMake(0, 0, 0, Y(51)) to:view save:YES];
    view2.backgroundColor = WHITE;
    label = [[UILabel alloc]init];
    [view2 addSubview:label];
    [label lt_setLeft:X(20) to:nil save:YES];
    [label lt_YcenterTo:nil save:YES];
    label.text = @"开户行名称";
    label.textColor = GRAY;
    label.font = [UIFont systemFontOfSize:14];
    _bankDetail = [[UITextField alloc]init];
    [view2 addSubview:_bankDetail];
    [_bankDetail lt_YcenterTo:nil save:YES];
    [_bankDetail lt_setLeft:X(120) to:nil Right:X(20) to:nil save:YES];
    _bankDetail.clearButtonMode = UITextFieldViewModeWhileEditing;
    _bankDetail.placeholder = @"例如：杭州华星路支行";
    _bankDetail.text = [dic objectForKey:@"bankDetail"];
    _bankDetail.font = FONT(14);
    UIButton *btn = [[UIButton alloc]init];
    [self.view addSubview:btn];
    [btn lt_Top:SunEdgesMake(Y(50), X(15), X(15), Y(44)) to:view2 save:YES];
    btn.clipsToBounds = YES;
    [btn setBackgroundColor:BLUE forState:UIControlStateNormal];
    [btn setBackgroundColor:[HXColor colorWithHexString:@"87CEFA"] forState:UIControlStateHighlighted];
    btn.layer.cornerRadius = 4;
    [btn setTitle:@"查询" forState:UIControlStateNormal];
    [btn setTitleColor:WHITE forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:17];
    [btn addTarget:self action:@selector(getList) forControlEvents:UIControlEventTouchUpInside];
    UILabel *mark = [[UILabel alloc]init];
    [self.view addSubview:mark];
    [mark lt_setTop:Y(40) to:btn save:YES];
    [mark lt_setLeft:X(25) to:nil Right:X(20) to:nil save:YES];
    mark.textColor = GRAY;
    mark.font = FONT(11);
    mark.numberOfLines = 0;
    mark.text = @"温馨提示：\n1、开户行名称：就是指办理开户手续的银行营业网点。\n2、如果您忘记了自己绑定的银行卡开户行名称，可以通过拨打银行电话详细咨询，或至网店查询。\n3、如果选择的开户行联行号不正确，恒丰银行可能无法将提现资金转入您绑定的银行卡中，务必选择正确。\n4、提现中有任何疑问，请联系小算盘财富客服：400-757-5858";
    [Sun labelSetLineHeight:Y(5) To:mark];
}

- (void)getList{
    if (_bankDetail.text.length == 0) {
        [[Sun shareSun]showMsg:@"请输入开户行名称"];
        return;
    }
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_BANKCODELIST];
    [[Sun shareSun]showActivity:self];
    [HttpRequest postURL:url withParam:@{@"name":[_bankDetail.text stringFromUTF8]} success:^(id requestDic, NSString *msg) {
        [[Sun shareSun]hideActivity];
        SunBankDetailListVC *vc = [[SunBankDetailListVC alloc]init];
        vc.data = [NSMutableArray arrayWithArray:[requestDic objectForKey:@"list"]];
        vc.name = _bankDetail.text;
        [self.navigationController pushViewController:vc animated:YES];
    } failure:^(NSString *errorInfo, int code) {
        [[Sun shareSun]hideActivity];
        [[Sun shareSun]showMsg:errorInfo];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
